<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Jhin" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="ONex B2B2C 二次开发之调用外部接口根据领导要求，输入VIN码返回对应车型的搜索结果
文件目录/custom/topc/controller/list.php或/app/topc/controller/list.php">
<meta property="og:type" content="article">
<meta property="og:title" content="ONex B2B2C 二次开发 调用外部接口">
<meta property="og:url" content="http://jhin.oschina.io/ShopEX/2016-10-21-06.ONex B2B2C 二次开发之调用外部接口.html">
<meta property="og:site_name" content="Jhin">
<meta property="og:description" content="ONex B2B2C 二次开发之调用外部接口根据领导要求，输入VIN码返回对应车型的搜索结果
文件目录/custom/topc/controller/list.php或/app/topc/controller/list.php">
<meta property="og:updated_time" content="2016-12-22T01:45:22.535Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ONex B2B2C 二次开发 调用外部接口">
<meta name="twitter:description" content="ONex B2B2C 二次开发之调用外部接口根据领导要求，输入VIN码返回对应车型的搜索结果
文件目录/custom/topc/controller/list.php或/app/topc/controller/list.php">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://jhin.oschina.io/ShopEX/2016-10-21-06.ONex B2B2C 二次开发之调用外部接口.html"/>


  <title> ONex B2B2C 二次开发 调用外部接口 | Jhin </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Jhin</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Jhin(ijhin@sina.com)</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-thinkphp">
          <a href="/categories/ThinkPHP-DOC" rel="section">
            
            ThinkPHP
          </a>
        </li>
      
        
        <li class="menu-item menu-item-mysql">
          <a href="/categories/MySQL" rel="section">
            
            MySQL
          </a>
        </li>
      
        
        <li class="menu-item menu-item-php">
          <a href="/categories/PHP" rel="section">
            
            PHP
          </a>
        </li>
      
        
        <li class="menu-item menu-item-linux">
          <a href="/categories/Linux" rel="section">
            
            Linux
          </a>
        </li>
      
        
        <li class="menu-item menu-item-nginx">
          <a href="/categories/Nginx" rel="section">
            
            Nginx
          </a>
        </li>
      
        
        <li class="menu-item menu-item-html">
          <a href="/categories/HTML" rel="section">
            
            HTML5
          </a>
        </li>
      
        
        <li class="menu-item menu-item-javascript">
          <a href="/categories/JavaScript" rel="section">
            
            JavaScript
          </a>
        </li>
      
        
        <li class="menu-item menu-item-onex">
          <a href="/categories/ONEX" rel="section">
            
            ONEX
          </a>
        </li>
      
        
        <li class="menu-item menu-item-yii">
          <a href="/categories/Yii2" rel="section">
            
            Yii2
          </a>
        </li>
      
        
        <li class="menu-item menu-item-shopex">
          <a href="/categories/ShopEX" rel="section">
            
            ShopEX
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                ONex B2B2C 二次开发 调用外部接口
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-10-21T14:51:55+08:00" content="2016-10-21">
              2016-10-21
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/ShopEX/" itemprop="url" rel="index">
                    <span itemprop="name">ShopEX</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="ONex-B2B2C-二次开发之调用外部接口"><a href="#ONex-B2B2C-二次开发之调用外部接口" class="headerlink" title="ONex B2B2C 二次开发之调用外部接口"></a>ONex B2B2C 二次开发之调用外部接口</h2><p>根据领导要求，输入VIN码返回对应车型的搜索结果</p>
<p>文件目录<code>/custom/topc/controller/list.php</code><br>或<br><code>/app/topc/controller/list.php</code></p>
<a id="more"></a>
<p>代码如下： </p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div><div class="line">188</div><div class="line">189</div><div class="line">190</div><div class="line">191</div><div class="line">192</div><div class="line">193</div><div class="line">194</div><div class="line">195</div><div class="line">196</div><div class="line">197</div><div class="line">198</div><div class="line">199</div><div class="line">200</div><div class="line">201</div><div class="line">202</div><div class="line">203</div><div class="line">204</div><div class="line">205</div><div class="line">206</div><div class="line">207</div><div class="line">208</div><div class="line">209</div><div class="line">210</div><div class="line">211</div><div class="line">212</div><div class="line">213</div><div class="line">214</div><div class="line">215</div><div class="line">216</div><div class="line">217</div><div class="line">218</div><div class="line">219</div><div class="line">220</div><div class="line">221</div><div class="line">222</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="meta">&lt;?php</span></div><div class="line"><span class="comment">/**</span></div><div class="line"> * ShopEx licence</div><div class="line"> *</div><div class="line"> * <span class="doctag">@copyright</span>  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)</div><div class="line"> * <span class="doctag">@license</span>  http://ecos.shopex.cn/ ShopEx License</div><div class="line"> */</div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">topc_ctl_list</span> <span class="keyword">extends</span> <span class="title">topc_controller</span> </span>&#123;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 每页搜索多少个商品</div><div class="line">     */</div><div class="line">    <span class="keyword">public</span> $limit = <span class="number">20</span>;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 最多搜索前100页的商品</div><div class="line">     */</div><div class="line">    <span class="keyword">public</span> $maxPages = <span class="number">100</span>;</div><div class="line"></div><div class="line"></div><div class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">index</span><span class="params">()</span></span></div><div class="line">    &#123;</div><div class="line">        <span class="keyword">$this</span>-&gt;setLayoutFlag(<span class="string">'gallery'</span>);</div><div class="line">        $objLibFilter = kernel::single(<span class="string">'topc_item_filter'</span>);</div><div class="line">        $postdata = input::get();</div><div class="line"></div><div class="line">        <span class="comment">//二次开发部分</span></div><div class="line">                </div><div class="line">        <span class="comment">// 正则匹配是否全为 字母或数字</span></div><div class="line">        <span class="keyword">if</span>(preg_match(<span class="string">'/^[a-zA-Z0-9]*/i'</span>, $postdata[<span class="string">'n'</span>]))&#123;</div><div class="line">            <span class="comment">//判断长度是否为17位</span></div><div class="line">            <span class="keyword">if</span>(mb_strlen($postdata[<span class="string">'n'</span>]) == <span class="number">17</span>)&#123;</div><div class="line">                <span class="comment">//小写字符转换为大写</span></div><div class="line">                $postdata[<span class="string">'n'</span>] = strtoupper($postdata[<span class="string">'n'</span>]);</div><div class="line">                </div><div class="line">                <span class="comment">//实例化接口</span></div><div class="line">                $http = <span class="keyword">new</span> base_httpclient();</div><div class="line">                $url  = <span class="string">'http://114.215.185.227:8080/PR/Model/queryModelByVinTo?uid=UserName&amp;vin='</span>.$postdata[<span class="string">'n'</span>];</div><div class="line">                $data = $http-&gt;get($url);</div><div class="line">                </div><div class="line">                <span class="comment">//json 转化为是数组</span></div><div class="line">                $data_array = json_decode($data,<span class="keyword">true</span>);</div><div class="line">                </div><div class="line">                <span class="comment">//判断是否为没有结果的vin</span></div><div class="line">                <span class="keyword">if</span>($data_array[<span class="string">'success'</span>])&#123;</div><div class="line">                    $data_array = $data_array[<span class="string">'data'</span>][<span class="number">0</span>];</div><div class="line">                    </div><div class="line">                    $postdata[<span class="string">'n'</span>] = $data_array[<span class="string">'PP'</span>] .<span class="string">' '</span>. $data_array[<span class="string">'CX'</span>] .<span class="string">' '</span>. $data_array[<span class="string">'PL'</span>] .<span class="string">' '</span>. $data_array[<span class="string">'NK'</span>];</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">//end</span></div><div class="line"></div><div class="line">        $params = $objLibFilter-&gt;decode($postdata);</div><div class="line">        <span class="comment">//echo '&lt;pre&gt;';print_r($params);exit();</span></div><div class="line">        $params[<span class="string">'use_platform'</span>] = <span class="string">'0,1'</span>;</div><div class="line">        <span class="comment">//判断自营  自营是1，非自营是0</span></div><div class="line">        <span class="keyword">if</span>($params[<span class="string">'is_selfshop'</span>]==<span class="string">'1'</span>)</div><div class="line">        &#123;</div><div class="line">            $pagedata[<span class="string">'isself'</span>] = <span class="string">'0'</span>;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">else</span></div><div class="line">        &#123;</div><div class="line">            $pagedata[<span class="string">'isself'</span>] = <span class="string">'1'</span>;</div><div class="line">        &#125;</div><div class="line">        <span class="comment">//如果不是从分类进入，并且没有关键字搜索则不能进入列表页</span></div><div class="line">        $params[<span class="string">'search_keywords'</span>] = htmlspecialchars(trim($params[<span class="string">'search_keywords'</span>]));</div><div class="line">        <span class="keyword">if</span>( <span class="keyword">empty</span>($params[<span class="string">'cat_id'</span>]) &amp;&amp; <span class="keyword">empty</span>($params[<span class="string">'search_keywords'</span>]) )</div><div class="line">        &#123;</div><div class="line">            <span class="keyword">return</span> redirect::back();</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">//默认图片</span></div><div class="line">        $pagedata[<span class="string">'image_default_id'</span>] = kernel::single(<span class="string">'image_data_image'</span>)-&gt;getImageSetting(<span class="string">'item'</span>);</div><div class="line"></div><div class="line">        <span class="comment">//搜索或者筛选获取商品</span></div><div class="line">        $searchParams = <span class="keyword">$this</span>-&gt;__preFilter($params);</div><div class="line"></div><div class="line">        <span class="comment">//面包屑数据</span></div><div class="line">        $breadcrumb = <span class="keyword">array</span>();</div><div class="line">        <span class="keyword">if</span>($searchParams[<span class="string">'cat_id'</span>] )</div><div class="line">        &#123;</div><div class="line">            $cat = app::get(<span class="string">'topc'</span>)-&gt;rpcCall(<span class="string">'category.cat.get.data'</span>,<span class="keyword">array</span>(<span class="string">'cat_id'</span>=&gt;intval($searchParams[<span class="string">'cat_id'</span>])));</div><div class="line">            $breadcrumb = <span class="keyword">array</span>(</div><div class="line">                [<span class="string">'url'</span>=&gt;url::action(<span class="string">'topc_ctl_topics@index'</span>,<span class="keyword">array</span>(<span class="string">'cat_id'</span>=&gt;$cat[<span class="string">'lv1'</span>][<span class="string">'cat_id'</span>])),<span class="string">'title'</span>=&gt;$cat[<span class="string">'lv1'</span>][<span class="string">'cat_name'</span>]],</div><div class="line">                [<span class="string">'url'</span>=&gt;<span class="string">''</span>,<span class="string">'title'</span>=&gt;$cat[<span class="string">'lv2'</span>][<span class="string">'cat_name'</span>]],</div><div class="line">                [<span class="string">'url'</span>=&gt;url::action(<span class="string">'topc_ctl_list@index'</span>,<span class="keyword">array</span>(<span class="string">'cat_id'</span>=&gt;$cat[<span class="string">'lv3'</span>][<span class="string">'cat_id'</span>])),<span class="string">'title'</span>=&gt;$cat[<span class="string">'lv3'</span>][<span class="string">'cat_name'</span>]],</div><div class="line">            );</div><div class="line">            <span class="keyword">if</span>($searchParams[<span class="string">'brand_id'</span>])</div><div class="line">            &#123;</div><div class="line">                $brands = app::get(<span class="string">'topc'</span>)-&gt;rpcCall(<span class="string">'category.brand.get.list'</span>,<span class="keyword">array</span>(<span class="string">'brand_id'</span>=&gt;$searchParams[<span class="string">'brand_id'</span>],<span class="string">'fields'</span>=&gt;<span class="string">'brand_id,brand_name'</span>));</div><div class="line">                $title = (count($brands) &gt;<span class="number">1</span>) ? <span class="string">"品牌："</span> : <span class="string">''</span>;</div><div class="line">                <span class="keyword">foreach</span>($brands <span class="keyword">as</span> $brand)</div><div class="line">                &#123;</div><div class="line">                    $title .= $brand[<span class="string">'brand_name'</span>].<span class="string">"、"</span>;</div><div class="line">                &#125;</div><div class="line">                $title = rtrim($title,<span class="string">"、"</span>);</div><div class="line">                $breadcrumb[] = [<span class="string">'url'</span>=&gt;<span class="string">''</span>,<span class="string">'title'</span>=&gt;$title];</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="keyword">if</span>($searchParams[<span class="string">'search_keywords'</span>])</div><div class="line">        &#123;</div><div class="line">            $breadcrumb = <span class="keyword">array</span>(</div><div class="line">                [<span class="string">'url'</span>=&gt;<span class="string">''</span>,<span class="string">'title'</span>=&gt;<span class="string">'全部商品'</span>],</div><div class="line">                [<span class="string">'url'</span>=&gt;<span class="string">''</span>,<span class="string">'title'</span>=&gt;$searchParams[<span class="string">'search_keywords'</span>]],</div><div class="line">            );</div><div class="line">        &#125;</div><div class="line">        $pagedata[<span class="string">'breadcrumb'</span>] = $breadcrumb;</div><div class="line"></div><div class="line">        $searchParams[<span class="string">'fields'</span>] = <span class="string">'item_id,title,image_default_id,price,promotion'</span>;</div><div class="line">        <span class="comment">//$itemsList = app::get('topc')-&gt;rpcCall('item.search',$searchParams);</span></div><div class="line">        <span class="keyword">try</span></div><div class="line">        &#123;</div><div class="line">            $itemsList = app::get(<span class="string">'topc'</span>)-&gt;rpcCall(<span class="string">'item.search'</span>,$searchParams);</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">catch</span>(<span class="keyword">Exception</span> $e)</div><div class="line">        &#123;</div><div class="line">            $msg = $e-&gt;getMessage();</div><div class="line">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;splash(<span class="string">'error'</span>,<span class="keyword">null</span>,$msg);</div><div class="line">        &#125;</div><div class="line">        <span class="comment">//检测是否有参加团购活动</span></div><div class="line">        <span class="keyword">if</span>($itemsList[<span class="string">'list'</span>])</div><div class="line">        &#123;</div><div class="line">            $itemsList[<span class="string">'list'</span>] = array_bind_key($itemsList[<span class="string">'list'</span>],<span class="string">'item_id'</span>);</div><div class="line">            $itemIds = array_keys($itemsList[<span class="string">'list'</span>]);</div><div class="line">            $activityParams[<span class="string">'item_id'</span>] = implode(<span class="string">','</span>,$itemIds);</div><div class="line">            $activityParams[<span class="string">'status'</span>] = <span class="string">'agree'</span>;</div><div class="line">            $activityParams[<span class="string">'end_time'</span>] = <span class="string">'bthan'</span>;</div><div class="line">            $activityParams[<span class="string">'start_time'</span>] = <span class="string">'sthan'</span>;</div><div class="line">            $activityParams[<span class="string">'fields'</span>] = <span class="string">'activity_id,item_id,activity_tag,price,activity_price'</span>;</div><div class="line">            $activityItemList = app::get(<span class="string">'topc'</span>)-&gt;rpcCall(<span class="string">'promotion.activity.item.list'</span>,$activityParams);</div><div class="line">            <span class="keyword">if</span>($activityItemList[<span class="string">'list'</span>])</div><div class="line">            &#123;</div><div class="line">                <span class="keyword">foreach</span>($activityItemList[<span class="string">'list'</span>] <span class="keyword">as</span> $key=&gt;$value)</div><div class="line">                &#123;</div><div class="line">                    $itemsList[<span class="string">'list'</span>][$value[<span class="string">'item_id'</span>]][<span class="string">'activity'</span>] = $value;</div><div class="line">                    $itemsList[<span class="string">'list'</span>][$value[<span class="string">'item_id'</span>]][<span class="string">'activity_price'</span>] = $value[<span class="string">'activity_price'</span>];</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">//根据条件搜索出最多商品的分类，进行显示渐进式筛选项</span></div><div class="line">        $filterItems = app::get(<span class="string">'topc'</span>)-&gt;rpcCall(<span class="string">'item.search.filterItems'</span>,$params);</div><div class="line">        <span class="comment">//渐进式筛选的数据</span></div><div class="line">        $pagedata[<span class="string">'screen'</span>] = $filterItems;</div><div class="line">        $pagedata[<span class="string">'items'</span>] = $itemsList[<span class="string">'list'</span>];<span class="comment">//根据条件搜索出的商品</span></div><div class="line">        $pagedata[<span class="string">'count'</span>] = $itemsList[<span class="string">'total_found'</span>]; <span class="comment">//根据条件搜索到的总数</span></div><div class="line"></div><div class="line">        <span class="comment">//已有的搜索条件</span></div><div class="line">        $tmpFilter = $params;</div><div class="line">        <span class="keyword">unset</span>($tmpFilter[<span class="string">'pages'</span>]);</div><div class="line">        $pagedata[<span class="string">'filter'</span>] = $objLibFilter-&gt;encode($tmpFilter);</div><div class="line"></div><div class="line">        <span class="comment">//分页</span></div><div class="line">        $pagedata[<span class="string">'pagers'</span>] = <span class="keyword">$this</span>-&gt;__pages($params[<span class="string">'pages'</span>], $pagedata[<span class="string">'count'</span>], $pagedata[<span class="string">'filter'</span>]);</div><div class="line">        <span class="comment">//已选择的搜索条件</span></div><div class="line">        $pagedata[<span class="string">'activeFilter'</span>] = $params;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;page(<span class="string">'topc/list/index.html'</span>, $pagedata);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 将post过的数据转换为搜索需要的参数</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> array $params</div><div class="line">     */</div><div class="line">    <span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">__preFilter</span><span class="params">($params)</span></span></div><div class="line">    &#123;</div><div class="line">        $searchParams = $params;</div><div class="line">        $searchParams[<span class="string">'page_no'</span>] = ($params[<span class="string">'pages'</span>] &gt;=<span class="number">1</span> || $params[<span class="string">'pages'</span>] &lt;= <span class="number">100</span>) ? $params[<span class="string">'pages'</span>] : <span class="number">1</span>;</div><div class="line">        $searchParams[<span class="string">'page_size'</span>] = <span class="keyword">$this</span>-&gt;limit;</div><div class="line"></div><div class="line">        $searchParams[<span class="string">'approve_status'</span>] = <span class="string">'onsale'</span>;</div><div class="line">        $searchParams[<span class="string">'buildExcerpts'</span>] = <span class="keyword">true</span>;</div><div class="line"></div><div class="line">        <span class="keyword">if</span>( $searchParams[<span class="string">'brand_id'</span>] &amp;&amp; is_array($searchParams[<span class="string">'brand_id'</span>]) )</div><div class="line">        &#123;</div><div class="line">            $searchParams[<span class="string">'brand_id'</span>] = implode(<span class="string">','</span>, $searchParams[<span class="string">'brand_id'</span>]);</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="keyword">if</span>( $searchParams[<span class="string">'prop_index'</span>] &amp;&amp; is_array($searchParams[<span class="string">'prop_index'</span>]) )</div><div class="line">        &#123;</div><div class="line">            $searchParams[<span class="string">'prop_index'</span>] = implode(<span class="string">','</span>, $searchParams[<span class="string">'prop_index'</span>]);</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">//排序</span></div><div class="line">        <span class="keyword">if</span>( !$params[<span class="string">'orderBy'</span>] )</div><div class="line">        &#123;</div><div class="line">            $params[<span class="string">'orderBy'</span>] = <span class="string">'sold_quantity desc'</span>;</div><div class="line">        &#125;</div><div class="line">        $searchparams[<span class="string">'orderBy'</span>] = $params[<span class="string">'orderBy'</span>];</div><div class="line"></div><div class="line">        <span class="keyword">return</span> $searchParams;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 分页处理</div><div class="line">     * <span class="doctag">@param</span> int $current 当前页</div><div class="line">     * <span class="doctag">@return</span> int $total  总页数</div><div class="line">     * <span class="doctag">@return</span> array $filter 查询条件</div><div class="line">     *</div><div class="line">     * <span class="doctag">@return</span> $pagers</div><div class="line">     */</div><div class="line">    <span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">__pages</span><span class="params">($current, $total, $filter)</span></span></div><div class="line">    &#123;</div><div class="line">        <span class="comment">//处理翻页数据</span></div><div class="line">        $current = ($current || $current &lt;= <span class="number">100</span> ) ? $current : <span class="number">1</span>;</div><div class="line">        $filter[<span class="string">'pages'</span>] = time();</div><div class="line"></div><div class="line">        <span class="keyword">if</span>( $total &gt; <span class="number">0</span> ) $totalPage = ceil($total/<span class="keyword">$this</span>-&gt;limit);</div><div class="line">        $pagers = <span class="keyword">array</span>(</div><div class="line">            <span class="string">'link'</span>=&gt;url::action(<span class="string">'topc_ctl_list@index'</span>,$filter),</div><div class="line">            <span class="string">'current'</span>=&gt;$current,</div><div class="line">            <span class="string">'total'</span>=&gt;$totalPage,</div><div class="line">            <span class="string">'token'</span>=&gt;time(),</div><div class="line">        );</div><div class="line">        <span class="keyword">return</span> $pagers;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>程序的开发思路如下：</p>
<p>减少开发强度，适用于接口相应较快。</p>
<p>1、首先，对用户的输入进行转义。</p>
<p>2、正则匹配输入的内容，是否为字母或者数字。</p>
<p>3、判断是否为17位。</p>
<p>4、小写转换为大写。</p>
<p>5、调用接口。</p>
<p>6、根据结果拼接搜索关键词。</p>
<p>附: <code>base_httpclient</code></p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span></div><div class="line"><span class="comment">/**</span></div><div class="line"> * ShopEx licence</div><div class="line"> *</div><div class="line"> * <span class="doctag">@copyright</span>  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)</div><div class="line"> * <span class="doctag">@license</span>  http://ecos.shopex.cn/ ShopEx License</div><div class="line"> * 本类使用推荐new class，不应使用kernel:single方法</div><div class="line"> */</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">base_httpclient</span></span>&#123;</div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">()</span></span>&#123;</div><div class="line">        <span class="keyword">$this</span>-&gt;netcore = kernel::single(<span class="string">'base_curl'</span>);</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">get</span><span class="params">($url,$headers=null,$callback=null,$ping_only=false)</span></span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;netcore-&gt;action(<span class="keyword">__FUNCTION__</span>,$url,$headers,$callback,<span class="keyword">null</span>,$ping_only);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">post</span><span class="params">($url,$data,$headers=null,$callback=null,$ping_only=false)</span></span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;netcore-&gt;action(<span class="keyword">__FUNCTION__</span>,$url,$headers,$callback,$data,$ping_only);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">set_timeout</span><span class="params">($timeout)</span></span>&#123;</div><div class="line">        <span class="keyword">$this</span>-&gt;netcore-&gt;set_timeout($timeout);</div><div class="line">        <span class="keyword">$this</span>-&gt;timeout = $timeout;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">action</span><span class="params">($action,$url,$headers=null,$callback=null,$data=null,$ping_only=false)</span></span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;netcore-&gt;action($action,$url,$headers,$callback,$data,$ping_only);</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">is_addr</span><span class="params">($ip)</span></span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;netcore-&gt;is_addr($ip);</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">upload</span><span class="params">($url,$files,$data,$headers=null,$callback=null,$ping_only=false)</span></span>&#123;</div><div class="line">        $boundary = <span class="string">'----ShopExFormBoundaryEsor2rdD1hne8INi'</span>;</div><div class="line">        $headers[<span class="string">'Content-Type'</span>]=<span class="string">'multipart/form-data; boundary='</span>.$boundary;</div><div class="line">        $formData = <span class="keyword">array</span>();</div><div class="line">        <span class="keyword">$this</span>-&gt;_http_query($formData,$data);</div><div class="line"></div><div class="line">        $output =<span class="string">''</span>;</div><div class="line">        <span class="keyword">foreach</span>($formData <span class="keyword">as</span> $k=&gt;$v)&#123;</div><div class="line">            $output .= <span class="string">'--'</span>.$boundary.<span class="string">"\r\n"</span>;</div><div class="line">            $output .= <span class="string">'Content-Disposition: form-data; name="'</span></div><div class="line">                .str_replace(<span class="string">'"'</span>,<span class="string">'\\\"'</span>,$k).<span class="string">"\"\r\n\r\n"</span>;</div><div class="line">            $output .= $v.<span class="string">"\r\n"</span>;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">foreach</span>($files <span class="keyword">as</span> $k=&gt;$v)&#123;</div><div class="line">            $output .= <span class="string">'--'</span>.$boundary.<span class="string">"\r\n"</span>;</div><div class="line">            $output .= <span class="string">'Content-Disposition: form-data; name="'</span></div><div class="line">                .str_replace(<span class="string">'"'</span>,<span class="string">'\\\"'</span>,$k).<span class="string">'"; filename="'</span>.basename($v).<span class="string">"\"\r\n"</span>;</div><div class="line">            $mime = function_exists(<span class="string">'mime_content_type'</span>)?mime_content_type($v):<span class="string">'application/octet-stream'</span>;</div><div class="line">            $output .= <span class="string">"Content-Type: $mime\r\n\r\n"</span>;</div><div class="line">            $output .= file_get_contents($v).<span class="string">"\r\n"</span>;</div><div class="line">        &#125;</div><div class="line">        $output .= <span class="string">'--'</span>.$boundary.<span class="string">"--\r\n"</span>;</div><div class="line"></div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;netcore-&gt;action(<span class="string">'post'</span>,$url,$headers,$callback,$output,$ping_only);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">_http_query</span><span class="params">(&amp;$return,$data,$prefix=null,$key=<span class="string">''</span>)</span></span></div><div class="line">    &#123;</div><div class="line">        $ret = <span class="keyword">array</span>();</div><div class="line">        <span class="keyword">foreach</span>((<span class="keyword">array</span>)$data <span class="keyword">as</span> $k =&gt; $v)&#123;</div><div class="line">            <span class="keyword">if</span>(is_int($k) &amp;&amp; $prefix != <span class="keyword">null</span>)&#123;</div><div class="line">                $k = $prefix.$k;</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">if</span>(!<span class="keyword">empty</span>($key))&#123;</div><div class="line">                $k = $key.<span class="string">"["</span>.$k.<span class="string">"]"</span>;</div><div class="line">            &#125;</div><div class="line"></div><div class="line">            <span class="keyword">if</span>(is_array($v) || is_object($v))&#123;</div><div class="line">                <span class="keyword">$this</span>-&gt;_http_query($return,$v,<span class="string">""</span>,$k);</div><div class="line">            &#125;<span class="keyword">else</span>&#123;</div><div class="line">                $return[$k]=$v;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">&#125;</div><div class="line"><span class="meta">?&gt;</span></div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/ShopEX/2016-10-21-02.ONex B2B2C 二次开发之程序目录结构.html" rel="next" title="ONex B2B2C 二次开发 程序目录结构">
                <i class="fa fa-chevron-left"></i> ONex B2B2C 二次开发 程序目录结构
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/ShopEX/2016-10-21-05.ONex B2B2C 二次开发之路由.html" rel="prev" title="ONex B2B2C 二次开发 路由">
                ONex B2B2C 二次开发 路由 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Jhin" />
          <p class="site-author-name" itemprop="name">Jhin</p>
          <p class="site-description motion-element" itemprop="description">Jhin 开发文档小结</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">22</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#ONex-B2B2C-二次开发之调用外部接口"><span class="nav-number">1.</span> <span class="nav-text">ONex B2B2C 二次开发之调用外部接口</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Jhin</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="/">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="/">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  



  




  
  

  

  

  

  


</body>
</html>
